<!doctype html>

<html>
<head>
  <link rel="shortcut icon" href="static/images/favicon.ico" type="image/x-icon">
  <title>queue_test.js (Closure Library API Documentation - JavaScript)</title>
  <link rel="stylesheet" href="static/css/base.css">
  <link rel="stylesheet" href="static/css/doc.css">
  <link rel="stylesheet" href="static/css/sidetree.css">
  <link rel="stylesheet" href="static/css/prettify.css">

  <script>
     var _staticFilePath = "static/";
     var _typeTreeName = "goog";
     var _fileTreeName = "Source";
  </script>

  <script src="static/js/doc.js">
  </script>


  <meta charset="utf8">
</head>

<body onload="grokdoc.onLoad();">

<div id="header">
  <div class="g-section g-tpl-50-50 g-split">
    <div class="g-unit g-first">
      <a id="logo" href="index.html">Closure Library API Documentation</a>
    </div>

    <div class="g-unit">
      <div class="g-c">
        <strong>Go to class or file:</strong>
        <input type="text" id="ac">
      </div>
    </div>
  </div>
</div>

<div class="clear"></div>

<h2><a href="local_closure_goog_structs_queue_test.js.html">queue_test.js</a></h2>

<pre class="prettyprint lang-js">
<a name="line1"></a>// Copyright 2006 The Closure Library Authors. All Rights Reserved.
<a name="line2"></a>//
<a name="line3"></a>// Licensed under the Apache License, Version 2.0 (the &quot;License&quot;);
<a name="line4"></a>// you may not use this file except in compliance with the License.
<a name="line5"></a>// You may obtain a copy of the License at
<a name="line6"></a>//
<a name="line7"></a>//      http://www.apache.org/licenses/LICENSE-2.0
<a name="line8"></a>//
<a name="line9"></a>// Unless required by applicable law or agreed to in writing, software
<a name="line10"></a>// distributed under the License is distributed on an &quot;AS-IS&quot; BASIS,
<a name="line11"></a>// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
<a name="line12"></a>// See the License for the specific language governing permissions and
<a name="line13"></a>// limitations under the License.
<a name="line14"></a>
<a name="line15"></a>goog.provide(&#39;goog.structs.QueueTest&#39;);
<a name="line16"></a>goog.setTestOnly(&#39;goog.structs.QueueTest&#39;);
<a name="line17"></a>
<a name="line18"></a>goog.require(&#39;goog.structs.Queue&#39;);
<a name="line19"></a>goog.require(&#39;goog.testing.jsunit&#39;);
<a name="line20"></a>
<a name="line21"></a>function stringifyQueue(q) {
<a name="line22"></a>  var values = q.getValues();
<a name="line23"></a>  var s = &#39;&#39;;
<a name="line24"></a>  for (var i = 0; i &lt; values.length; i++) {
<a name="line25"></a>    s += values[i];
<a name="line26"></a>  }
<a name="line27"></a>  return s;
<a name="line28"></a>}
<a name="line29"></a>
<a name="line30"></a>function createQueue() {
<a name="line31"></a>  var q = new goog.structs.Queue();
<a name="line32"></a>  q.enqueue(&#39;a&#39;);
<a name="line33"></a>  q.enqueue(&#39;b&#39;);
<a name="line34"></a>  q.enqueue(&#39;c&#39;);
<a name="line35"></a>  return q;
<a name="line36"></a>}
<a name="line37"></a>
<a name="line38"></a>function testConstructor() {
<a name="line39"></a>  var q = new goog.structs.Queue();
<a name="line40"></a>  assertTrue(&#39;testConstructor(), queue should be empty initially&#39;, q.isEmpty());
<a name="line41"></a>  assertEquals(&#39;testConstructor(), count should be 0&#39;, q.getCount(), 0);
<a name="line42"></a>  assertEquals(&#39;testConstructor(), head element should be undefined&#39;, q.peek(),
<a name="line43"></a>      undefined);
<a name="line44"></a>}
<a name="line45"></a>
<a name="line46"></a>function testCount() {
<a name="line47"></a>  var q = createQueue();
<a name="line48"></a>  assertEquals(&#39;testCount(), count should be 3&#39;, q.getCount(), 3);
<a name="line49"></a>  q.enqueue(&#39;d&#39;);
<a name="line50"></a>  assertEquals(&#39;testCount(), count should be 4&#39;, q.getCount(), 4);
<a name="line51"></a>  q.dequeue();
<a name="line52"></a>  assertEquals(&#39;testCount(), count should be 3&#39;, q.getCount(), 3);
<a name="line53"></a>  q.clear();
<a name="line54"></a>  assertEquals(&#39;testCount(), count should be 0&#39;, q.getCount(), 0);
<a name="line55"></a>}
<a name="line56"></a>
<a name="line57"></a>function testEnqueue() {
<a name="line58"></a>  var q = new goog.structs.Queue();
<a name="line59"></a>  q.enqueue(&#39;a&#39;);
<a name="line60"></a>  assertEquals(&#39;testEnqueue(), count should be 1&#39;, q.getCount(), 1);
<a name="line61"></a>  q.enqueue(&#39;b&#39;);
<a name="line62"></a>  assertEquals(&#39;testEnqueue(), count should be 2&#39;, q.getCount(), 2);
<a name="line63"></a>  assertEquals(&#39;testEnqueue(), head element should be a&#39;, q.peek(), &#39;a&#39;);
<a name="line64"></a>  q.dequeue();
<a name="line65"></a>  assertEquals(&#39;testEnqueue(), count should be 1&#39;, q.getCount(), 1);
<a name="line66"></a>  assertEquals(&#39;testEnqueue(), head element should be b&#39;, q.peek(), &#39;b&#39;);
<a name="line67"></a>}
<a name="line68"></a>
<a name="line69"></a>function testDequeue() {
<a name="line70"></a>  var q = createQueue();
<a name="line71"></a>  var head = q.dequeue();
<a name="line72"></a>  assertEquals(&#39;testDequeue(), should return a&#39;, head, &#39;a&#39;);
<a name="line73"></a>  q.dequeue();
<a name="line74"></a>  head = q.dequeue();
<a name="line75"></a>  assertEquals(&#39;testDequeue(), should return c&#39;, head, &#39;c&#39;);
<a name="line76"></a>  assertTrue(&#39;testDequeue(), queue should be empty&#39;, q.isEmpty());
<a name="line77"></a>  head = q.dequeue();
<a name="line78"></a>  assertEquals(&#39;testDequeue(), should return undefined for empty queue&#39;, head,
<a name="line79"></a>      undefined);
<a name="line80"></a>}
<a name="line81"></a>
<a name="line82"></a>function testPeek() {
<a name="line83"></a>  var q = createQueue();
<a name="line84"></a>  var head = q.peek();
<a name="line85"></a>  assertEquals(&#39;testPeek(), should return a&#39;, head, &#39;a&#39;);
<a name="line86"></a>  var head2 = q.dequeue();
<a name="line87"></a>  assertEquals(&#39;testPeek(), dequeue should return peek() result&#39;, head, head2);
<a name="line88"></a>  head = q.peek();
<a name="line89"></a>  assertEquals(&#39;testPeek(), should return b&#39;, head, &#39;b&#39;);
<a name="line90"></a>  q.clear();
<a name="line91"></a>  head = q.peek();
<a name="line92"></a>  assertEquals(&#39;testPeek(), should return undefined for empty queue&#39;, head,
<a name="line93"></a>      undefined);
<a name="line94"></a>}
<a name="line95"></a>
<a name="line96"></a>function testClear() {
<a name="line97"></a>  var q = createQueue();
<a name="line98"></a>  q.clear();
<a name="line99"></a>  assertTrue(&#39;testClear(), queue should be empty&#39;, q.isEmpty());
<a name="line100"></a>}
<a name="line101"></a>
<a name="line102"></a>function testQueue() {
<a name="line103"></a>  var q = createQueue();
<a name="line104"></a>  assertEquals(&#39;testQueue(), contents must be abc&#39;, stringifyQueue(q), &#39;abc&#39;);
<a name="line105"></a>}
<a name="line106"></a>
<a name="line107"></a>function testRemove() {
<a name="line108"></a>  var q = createQueue();
<a name="line109"></a>  assertEquals(&#39;testRemove(), contents must be abc&#39;, stringifyQueue(q), &#39;abc&#39;);
<a name="line110"></a>
<a name="line111"></a>  q.dequeue();
<a name="line112"></a>  assertEquals(&#39;testRemove(), contents must be bc&#39;, stringifyQueue(q), &#39;bc&#39;);
<a name="line113"></a>
<a name="line114"></a>  q.enqueue(&#39;a&#39;);
<a name="line115"></a>  assertEquals(&#39;testRemove(), contents must be bca&#39;, stringifyQueue(q), &#39;bca&#39;);
<a name="line116"></a>
<a name="line117"></a>  assertTrue(&#39;testRemove(), remove should have returned true&#39;, q.remove(&#39;c&#39;));
<a name="line118"></a>  assertEquals(&#39;testRemove(), contents must be ba&#39;, stringifyQueue(q), &#39;ba&#39;);
<a name="line119"></a>
<a name="line120"></a>  assertTrue(&#39;testRemove(), remove should have returned true&#39;, q.remove(&#39;b&#39;));
<a name="line121"></a>  assertEquals(&#39;testRemove(), contents must be a&#39;, stringifyQueue(q), &#39;a&#39;);
<a name="line122"></a>
<a name="line123"></a>  assertFalse(&#39;testRemove(), remove should have returned false&#39;, q.remove(&#39;b&#39;));
<a name="line124"></a>  assertEquals(&#39;testRemove(), contents must be a&#39;, stringifyQueue(q), &#39;a&#39;);
<a name="line125"></a>
<a name="line126"></a>  assertTrue(&#39;testRemove(), remove should have returned true&#39;, q.remove(&#39;a&#39;));
<a name="line127"></a>  assertEquals(&#39;testRemove(), contents must be empty&#39;, stringifyQueue(q), &#39;&#39;);
<a name="line128"></a>}
<a name="line129"></a>
<a name="line130"></a>function testContains() {
<a name="line131"></a>  var q = createQueue();
<a name="line132"></a>  assertTrue(&#39;testContains(), contains should have returned true&#39;,
<a name="line133"></a>      q.contains(&#39;a&#39;));
<a name="line134"></a>  assertFalse(&#39;testContains(), contains should have returned false&#39;,
<a name="line135"></a>      q.contains(&#39;foobar&#39;));
<a name="line136"></a>}
</pre>


</body>
</html>
